package com.cskaoyan.bean;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

/**
 * @author stone
 * @date 2022/07/06 11:32
 */
@Component
public class LifeCycleBean implements BeanNameAware, BeanFactoryAware, ApplicationContextAware {
    public LifeCycleBean() {
        System.out.println("lifecycleBean的实例化");
    }

    User user;

    String username;

    @Autowired
    // User user;
    public void setUser(User user) {
        System.out.println("属性值设置");
        this.user = user;
    }

    // 通常使用Aware接口，意味着该类下要增加对应的成员变量
    // 要通过set方法给它做赋值
    String beanName;
    BeanFactory beanFactory;
    ApplicationContext applicationContext;

    @Override
    public void setBeanName(String beanName) {
        System.out.println("setBeanName");
        this.beanName = beanName;
    }

    @Override
    public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
        System.out.println("setBeanFactory");
        this.beanFactory = beanFactory;
    }

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        System.out.println("setApplicationContext");
        this.applicationContext = applicationContext;
    }

    public void setUsername(String username) {
        this.username = username;
    }
}
